<?php 
namespace Common\Logic;
class ContentsLogic{
	private $m;
	private $Contentsstandard;
	private $standard;
	
	function __construct(){
		$this->m = D('Contents');
		$this->Contentsstandard = D('ContentsStandard');
		$this->standard = D('Standard');
	}
	
	/**
	 * 根据ID找内容
	 * @param unknown $id
	 */
	public function _get_content($id){
		return $this->m->relation(true)->find($id);
	}
	
	/**
	 * 查找内容
	 * @param unknown $map
	 * @param unknown $start
	 * @param unknown $end
	 * @param unknown $order
	 */
	public function _get_Contents($map,$start,$end,$order){
		if(!$start) $start = 1;
		if(!$end) $end = 10;
		if(!$order) $order = 'listorder desc';
		return $this->m->where($map)->limit($start,($end-$start+1))->order($order)->relation(true)->select();
		
	}
	
	/**
	 * 根据分类获得内容
	 * @param unknown $cid
	 * @param unknown $start
	 * @param unknown $end
	 * @param unknown $order
	 */
	public function _get_cid_Contents($cid,$start,$end,$order) {
		$map['cid'] = $cid;
		return $this->_get_Contents($map,$start,$end,$order);
	}
	
	/**
	 * 保存规格属性
	 * @param unknown $id
	 * @param unknown $post
	 */
	public function _save_standard($id,$post){
		$data['id'] = $id;
		if(!$post['standard']) $post['standard'] = 0;
		if($post['standard'] !== '-1'){
			$data['standard_model'] = $this->standard->where('id = '.$post['standard'])->getField('guige');
		}
		$data['standard_id'] = $post['standard'];
		$data['standard_content'] = json_encode($post['gg']);
		if($this->Contentsstandard->find($data['id'])){
			$this->Contentsstandard->save($data);
		}else{
			$this->Contentsstandard->add($data);
		}
		
	}
	
	/**
	 * 删除规格属性
	 * @param unknown $id
	 * @return boolean
	 */
	public function _del_standard($id){
		if($this->Contentsstandard->where('id = '.$id)->delete()){
			return true;
		}else{
			return false;	
		}
	}
}
?>